(function($){
    function SuperSimpleSlideDeck( deckFrame ){
		var superSimpleDeckFrame = $(deckFrame);
		var superSimpleDeckFrameHeight = superSimpleDeckFrame.outerHeight();
		var footer;
		var footerHeight = 0;
		var superSimplePrev;
		var superSimpleNext;
		var superSimpleGoTo;
		var navigation = '<div class="slidedeckFooter"><div class="navigation"><a class="prevSlide" href="#prev">&larr;</a><a class="nextSlide" href="#next">&rarr;</a></div><span id="space1">&nbsp;</span><input id="currSlide" type="text" maxlength="2" size="2" value="1"/><span id="totalSlides"></span>&nbsp;&nbsp;&nbsp;<BUTTON TYPE="submit" id="go" >Go</BUTTON><span id="space2">&nbsp;</span><BUTTON TYPE="submit" id="nav_first" >First</BUTTON>&nbsp;&nbsp;<BUTTON TYPE="submit" id="nav_last" >Last</BUTTON></div>';
		
		var superSimpleDeck = superSimpleDeckFrame.find('.slidedeck').slidedeck();
		
		function updateDisabledNavigation(){
		
			if(superSimpleDeck.options.cycle == false){
				superSimpleNext.removeClass('disabled');
				superSimplePrev.removeClass('disabled');
				if( superSimpleDeck.current == 1 ){
					superSimplePrev.addClass('disabled');
				}
				if( superSimpleDeck.current == superSimpleDeck.slides.length ){
					superSimpleNext.addClass('disabled');
				}							
			}				
		}
		
		superSimpleDeck.loaded(function(){
			console.log("loaded");
			if( superSimpleDeckFrame.find('.slidedeckFooter').length ){
				superSimpleDeckFrame.find('.slidedeckFooter').remove();
			}
			superSimpleDeckFrame.append(navigation);
			
			footer = superSimpleDeckFrame.find( '.slidedeckFooter' );
			footerHeight = footer.outerHeight();					
			
			superSimplePrev = superSimpleDeckFrame.find('a.prevSlide');
			superSimpleNext = superSimpleDeckFrame.find('a.nextSlide');
			superSimpleGoTo = superSimpleDeckFrame.find('input#currSlide');
			
			superSimplePrev.click(function(event){
				event.preventDefault();    				
				superSimpleDeck.prev();				
			});
			
			superSimpleNext.click(function(event){
				event.preventDefault();    				
				superSimpleDeck.next();				
			});
			
			updateDisabledNavigation();
		
			$('span#totalSlides').replaceWith('<span id="totalSlides"> &nbsp; / &nbsp; ' + superSimpleDeck.slides.length + '</span>');
			
			$('#nav_first').click(function(event){
				// Stuff to do when "First" is clicked.
				superSimpleDeck.goTo(1);
			});
			$('#nav_last').click(function(event){
				// Stuff to do when "Prev" is clicked.
				superSimpleDeck.goTo(superSimpleDeck.slides.length);
			});
			$('#go').click(function(event){
				// Stuff to do when "go" is clicked.
				superSimpleDeck.goTo(parseInt($("input#currSlide").val(),10));
				if (superSimpleDeck.current == 1) {
					audioPlayer.seek(0);
				}else {
					audioPlayer.seek((cuepoints_rounded[myDeck.current-2])/1000);
				}
				
			});
		});	
		
		superSimpleDeck.options.complete = function(){
			updateDisabledNavigation();
			if (document.getElementById('currSlide').value != superSimpleDeck.current){
					$('#currSlide').replaceWith('<input id="currSlide" type="text" maxlength="2" size="2" value="' +
					 superSimpleDeck.current + '"/>');
			}
		}
	}
	
	$(document).ready(function(){
		for(var i=0, decks=$('.skin'); i<decks.length; i++){
			var thisDeck = decks[i];
			
			if(typeof(thisDeck.SlideDeck_skinSuperSimple) == 'undefined'){
				thisDeck.SlideDeck_skinSuperSimple = SuperSimpleSlideDeck( thisDeck );
			}
		}
	});    
})(jQuery);
